let nums = [1,3,-1,-3,5,3,6,7];
let k = 4;

var medianSlidingWindow = function(nums, k) {
    let result = []
    for(let i=0;i<=nums.length-k;i++){
        let arr = nums.slice(i,i+k).sort((a,b)=> a-b) 
        if(k%2==1){
            let mid = Math.floor(arr.length/2)
             result.push(arr[mid])
        }else{
            let up = arr.length/2-1
            let down = arr.length/2
            result.push((arr[up]+arr[down])/2)
        }
    }
    return result
};

console.log(medianSlidingWindow(nums,k));




